import request from "@/utils/request";

let cacheEmployeeList = [];

export default {
  name: 'EmployeeMixin',
  data(){
    return {
      employeeList: [],
    }
  },
  computed: {
    employeeSaleList(){
      const jobName = 'salesperson';
      return this.employeeList.filter(item => item.job.includes(jobName));
    },
    employeeCustomerList(){
      const jobName = 'customerservice';
      return this.employeeList.filter(item => item.job.includes(jobName));
    },
  },
  created() {
    this.getEmployeeList();
  },
  methods: {
    getEmployeeList(){
      if(cacheEmployeeList.length > 0){
        this.employeeList = cacheEmployeeList
      }else{
        request({
          url: '/employee/getAllEmployee'
        })
          .then(res=>{
            this.employeeList = res.data
            cacheEmployeeList = res.data
          })
      }

    }
  }
}
